home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / textfile.swg / 0017_Cleaning a Text file.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-08-27  |  3.2 KB  |  130 lines

  1. {
  2. MATT GIWER
  3.  
  4. It is designed to clean up Files you might wish to capture from Real time
  5. chat.  It gets rid of all those back spaces and recreates a readable File
  6. that appears as though no typos were made by anyone.
  7.  
  8. {$M 65520,0,655360 }
  9. Program capture_strip;
  10.  
  11. Uses
  12.   Dos, Crt;
  13.  
  14. Const
  15.   copyright : String[80] =
  16.                 'copyright 1988 and 1991 by Matt Giwer, all rights reserved';
  17.   name : String[20] = 'CAPture CLeaN ';
  18.   ver  : String[5]  = '1.2';
  19.  
  20. Var
  21.   in_File,
  22.   out_File    : Text;
  23.   in_name,
  24.   out_name    : String[30];
  25.   in_String,
  26.   out_String  : String[250];
  27.   i, k, l     : Integer;
  28.   ch          : Char;
  29.   count       : Integer;
  30.   Files       : Array[1..50] of String[20];
  31.   in_Array,
  32.   out_Array   : Array[1..100] of String[250];
  33.   Array_count : Byte;
  34.  
  35. Procedure clear_Strings;
  36. Var
  37.   i : Byte;
  38. begin
  39.   for i := 1 to 100 do
  40.   begin
  41.     in_Array[i]  := '';
  42.     out_Array[i] := '';
  43.   end;
  44. end;
  45.  
  46. Procedure strip_File;
  47. begin
  48.   For l := 1 to Array_count do
  49.   begin
  50.     out_String := '';
  51.     in_String  := in_Array[l];
  52.     For i := 1 to length(in_String) do
  53.     {if it is any except a backspace then add it to the output String}
  54.     begin
  55.       if ord(in_String[i]) <> 8  then
  56.         out_String := out_String + in_String[i];
  57.       {if it is a backspace than the intention was to remove the last Character
  58.       in the String that was added above.  Thus the BS is a signal to remove the
  59.       last Character added above.}
  60.       if ord(in_String[i]) = 8 then
  61.         delete(out_String, length(out_String), 1);
  62.     end;
  63.     While (out_String[length(out_String)] = ' ') do
  64.       delete(out_String, length(out_String), 1);
  65.     out_Array[l] := out_String;
  66.   end;
  67. end;
  68.  
  69. Procedure fill_Array;
  70. begin
  71.   While not eof(in_File) do
  72.   begin
  73.     clear_Strings;
  74.     Array_count := 1;
  75.     While (not eof(in_File) and (Array_count < 100) ) do
  76.     begin
  77.       readln(in_File, in_Array[Array_count]);
  78.       Array_count := Array_count + 1;
  79.     end;
  80.     strip_File;
  81.     For l := 1 to Array_count do
  82.       Writeln(out_File, out_Array[l]);
  83.   end;
  84. end;
  85.  
  86. begin
  87.   Writeln(name,ver);
  88.   Writeln(copyright);
  89.   For count := 1 to 50 do
  90.     Files[count] := '                    ';
  91.   clear_Strings;
  92.   Writeln;
  93.   if paramcount < 1 then {if command line empty}
  94.   begin
  95.     Writeln('Only Filenames are accepted, no extenders');
  96.     Writeln('Output File will be  .CLN');
  97.     Write('Enter File name.  '); readln(in_name);
  98.   end
  99.   else   {else get an Array of the parameters}
  100.   begin
  101.     For i := 1 to paramcount do
  102.       Files[i] := paramstr(i)  {! count vice i}
  103.   end;
  104.   if paramcount < 1 then
  105.   begin
  106.     assign(in_File, in_name);
  107.     reset(in_File);
  108.     assign(out_File, in_name + '.CLN');
  109.     reWrite(out_File);
  110.     Write('Working on ', in_name:20);
  111.     fill_Array;
  112.     Writeln;
  113.   end
  114.   else
  115.   begin
  116.     For count := 1 to paramcount do
  117.     begin
  118.       in_name := paramstr(count);
  119.       assign(in_File, in_name);
  120.       reset(in_File);
  121.       assign(out_File, in_name + '.CLN');
  122.       reWrite(out_File);
  123.       Write('Working on ', paramstr(count):20);
  124.       fill_Array;
  125.       Writeln;
  126.       close(in_File);
  127.       close(out_File);
  128.     end;
  129.   end;
  130. end.